<?php

namespace App\Logics;


use App\Models\GoodsComment;
use App\Models\User;

class GoodsCommentLogic extends Logic
{

    // 列表

    // 详情

    // 修改

    // 删除
    // TODO 操作日志

    // 快讯的评论
    public function lists()
    {
        $opt      = $this->option();
        $event_id = $opt->getData('event_id', 0, 'intval');
        $page     = $opt->getData('page', 1, 'intval');
        $rows     = $opt->getData('rows', 15, 'intval');
        if(empty($event_id)){
            //return $this->_returnFail('请指定需求编号!');
            return $this->_returnFail('select_operation_id');
        }

        $where   = ['article_id' => $event_id, 'channel' => 'event', 'verify' => 1]; // 'pid' => 0,
        $comment = new GoodsComment();

        //$where   = ['event_id' => $event_id, 'verify' => 1]; // 'pid' => 0,
        //$comment = new EventComment();

        $result = $comment->listPage($where, $page, $rows);
        if($result['list']){
            $uids   = array_column($result['list'], 'uid');
            $userDb = new User();
            $users  = $userDb->getListInIdsCache($uids);
            foreach($result['list'] as $key => $item){
                $_uid  = $item['uid'];
                $_info = $users[$_uid] ?? [];
                if($_info){
                    $_info['head_img'] = $this->getHeadImg($_info['head_img'] ?? '');
                }

                // 整理
                $result['list'][$key]['user'] = $_info;
            }
        }

        return $result;
    }


}

